Local projections with a continuous state ========================================== A state-dependent local projection (see :doc:`Main Local Projections`) interacts every regressor of horizon ``k`` with the weight of state 1 and with its complement: .. math:: y_{i,t+k} = w_{t-d}\, x_t' b_{1,i,k} + (1 - w_{t-d})\, x_t' b_{2,i,k} + u_{i,k,t} :math:`x_t` collects the regressors of the projection: :math:`y_t` in lpvar mode or the measured shock in shock mode, the lags, the constant and the deterministic regressors. With a threshold, :math:`w_{t-d}` is an indicator, zero or one. With ``state.value = 'weights'`` it is the state series itself, read as a number between zero and one: the weight of state 1, state 2 taking one minus it. A smooth transition between the states, such as a logistic function of a business-cycle indicator, is supplied this way. The two coefficient blocks are the responses where the weight is one (state 1) and where it is zero (state 2). At a weight :math:`w` in between the response is :math:`w\,b_1 + (1-w)\,b_2`. Both blocks come from one regression, not from two separate samples, and a date with an interior weight contributes to both, so the two state responses are correlated. In shock mode ``estimate`` reports that covariance, horizon by horizon, and the difference of the two states with its standard error. An endpoint that the weights rarely come near is estimated mostly by extrapolation. .. contents:: :local: :depth: 2 The call --------- The weights are a series of ``db``, named in ``state.variable``:: w = utils.smooth_transition.logistic(z, 3, 0); % 1./(1+exp(-3*(z-0))) db.w = w; est = rise.engine.var.lptools.estimate(db, {'y'}, ... horizons = 0:6, ... lag_length = 1, ... shock = 's', ... state = struct('variable','w','value','weights','delay',1)); ``utils.smooth_transition.logistic(z,g,c)`` is :math:`1/(1+e^{-g(z-c)})`. ``estimate`` takes the weights as data: it does not choose or estimate the slope and the center of the transition. The weight series follows the rules of the other series of ``db``: plain vectors of the same length, or time series of one page starting on the same date. .. list-table:: :header-rows: 1 :widths: 28 72 * - Field of ``state`` - Meaning * - ``variable`` - name of the weight series in ``db`` * - ``value`` - ``'weights'``: the series is the weight of state 1. A number or ``'median'`` keeps its meaning: the indicator of the series above that threshold. * - ``delay`` - ``d``: the regression at date ``t`` uses the weight of date ``t-d``. Default 1; an integer from 0 to the sample size minus one. A weight must be a real number between zero and one, or ``NaN``. A weight outside [0, 1], infinite or complex is an error (``lptools:estimate:badWeights``). A ``NaN`` weight, or a delay reaching before the sample, leaves the row out, as an unknown state does with a threshold. Weights of zero and one give the threshold estimate exactly. A weight that never moves identifies nothing: with :math:`w` the same at every date the two blocks are proportional, and the states cannot be told apart. The projection is then refused: the estimate is empty and the second output is ``LP_NOT_IDENTIFIED`` (802). A sample with no usable row, all its weights ``NaN`` for example, returns ``NO_DATA`` (500). With one output the empty estimate comes without a message, so ask for the return code:: [est, retcode] = rise.engine.var.lptools.estimate(db, {'y'}, ...); if retcode disp(decipher(retcode)) end What comes out --------------- Both modes return one block per state: ``B{1}`` and ``B{2}`` in lpvar mode, the reduced-form responses where the weight is one and zero, which ``identified_set`` takes as it takes a threshold estimate; ``beta{1}`` and ``beta{2}`` in shock mode. In lpvar mode both states have the identity at horizon 0 and share one pooled ``Sigma``, as with a threshold, and their uncertainty is an identified set, not a band. .. list-table:: :header-rows: 1 :widths: 30 70 * - Field - Contents * - ``beta{r}(i,k+1)`` - shock mode: response of variable ``i`` at horizon ``k`` in state ``r``, in units of ``y_i`` per unit of the shock series * - ``beta_se{r}(i,k+1)`` - its Newey-West standard error, the square root of the diagonal of ``beta_cov`` * - ``beta_cov{k+1}(r,s,i)`` - shock mode: covariance between the state-``r`` and state-``s`` responses of variable ``i`` at horizon ``k``; ``nstate`` by ``nstate`` by ``n`` * - ``beta_difference(i,k+1)`` - shock mode, two states: state 1 minus state 2 * - ``beta_difference_se(i,k+1)`` - its standard error, :math:`\sqrt{V_{11}+V_{22}-V_{12}-V_{21}}` from ``beta_cov{k+1}(:,:,i)`` * - ``hac_lags`` - shock mode: the truncation requested at each horizon, ``1`` by ``K+1`` * - ``I`` - the weights of the rows used * - ``share_state1`` - the mean of ``I`` * - ``threshold`` - ``NaN`` with weights ``beta_cov`` describes dependence within a horizon, between the two states, for one variable at a time. It says nothing about dependence across horizons or across variables, and gives no simultaneous band over the horizons. The standard error of the difference uses both cross-state terms: with interior weights they are not zero, and adding the two standard errors in quadrature gets it wrong. The response at an interior weight ``w`` has its variance in the same block:: mix = [w; 1-w]; response = w*est.beta{1}(i,k+1) + (1-w)*est.beta{2}(i,k+1); variance = mix' * est.beta_cov{k+1}(:,:,i) * mix; In lpvar mode ``beta_cov``, ``beta_difference`` and ``beta_difference_se`` are empty. The HAC truncation, horizon by horizon --------------------------------------- The residual at horizon ``k`` overlaps the next ``k`` periods. ``hac_lags`` sets the Newey-West truncation: * empty (the default): ``k+1`` at horizon ``k``; * one nonnegative integer: the same truncation at every horizon; * ``K+1`` nonnegative integers: one per horizon, indexed by ``0:K``. Anything else is an error (``lptools:estimate:badHacLags``). The truncation changes the standard errors and covariances, not the responses. ``est.hac_lags`` reports the truncation requested at each horizon; the one used is at most the number of dates the rows of that horizon span, minus one. The scores are paired by their dates, so a row left out for a missing value contributes nothing at its date, and the rows on both sides of the gap are not neighbors. An example with a known answer ------------------------------- The tutorial ``rise-modern-tutorials/ModelShapes/local_projections/howto_continuous_state.m`` simulates 2,000 observations of .. math:: z_t = 0.9 z_{t-1} + \sqrt{0.19}\,u_t, \qquad w_t = \frac{1}{1+e^{-3 z_t}}, \qquad y_t = 0.6\,y_{t-1} + \bigl(w_{t-1}\cdot 1 + (1-w_{t-1})\cdot 0.2\bigr) s_t + 0.5\,e_t, with :math:`s_t` a measured shock of standard deviation one. The response of :math:`y` at horizon ``k`` to one unit of :math:`s` is :math:`0.6^k` where the weight is one and :math:`0.2 \times 0.6^k` where it is zero. The projection uses the weights with delay 1, one lag of :math:`y` and a constant, on 1,993 observations; the mean weight of those rows, ``share_state1``, is 0.490. At horizon 0 RISE returns: .. list-table:: :header-rows: 1 :widths: 34 22 22 22 * - Impact response of y to one unit of s - State 1 - State 2 - State 1 minus state 2 * - Truth - 1.000 - 0.200 - 0.800 * - Continuous weights, ``value = 'weights'`` - 1.007 (0.019) - 0.216 (0.018) - 0.792 (0.030) * - Threshold, :math:`z_{t-1} > 0` - 0.858 - 0.355 - 0.504 Standard errors in parentheses. The threshold puts each date wholly in one state, although 57% of the weights lie between 0.1 and 0.9: each threshold state mixes the two responses, and the difference is pulled toward zero. The correlation of the two weighted impact estimates is -0.36, so the standard error of the difference, 0.030, is larger than the two standard errors added in quadrature, 0.026. A projection without a state returns 0.600 on impact, the response at the mean weight (:math:`0.490 \times 1.007 + 0.510 \times 0.216 = 0.604`, standard error 0.010). The tutorial also shows the horizon-by-horizon responses against their targets, a truncation of ``2(k+1)`` that leaves the responses unchanged, and the refusal of a constant weight.